﻿
using UnityEngine;

namespace XFGameFramework.TweenSystem
{

    /// <summary>
    /// Transform动画拓展
    /// </summary>
    public static class TransformExtensions
    {


        /// <summary>
        /// 渐变position
        /// </summary>
        /// <param name="transform">Transform对象</param>
        /// <param name="target">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义的缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟</param>
        /// <param name="loopCount">循环次数</param>
        /// <returns></returns>
        public static TweenerCore<Vector3> TweenPosition(this Transform transform, Vector3 target, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1)
        { 
            return TweenManager.ComponentTween(transform, transform.position, target, duration, loop, ease, curve, ingoreTimeScale, OnTweenPosition, delay,0,loopCount);
        }

        internal static void OnTweenPosition(TweenerCore<Vector3> tweener)
        {
            if (tweener.Component is Transform)
            {
                Transform transform = tweener.Component as Transform;
                transform.position = tweener.Value;
            }
        }

        /// <summary>
        /// 渐变localPosition
        /// </summary>
        /// <param name="transform">Transform对象</param>
        /// <param name="target">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义的缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟</param>
        /// <param name="loopCount">循环次数</param>
        /// <returns></returns>
        public static TweenerCore<Vector3> TweenLocalPosition(this Transform transform, Vector3 target, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1)
        { 
            return TweenManager.ComponentTween(transform, transform.localPosition, target, duration, loop, ease, curve, ingoreTimeScale, OnTweenLocalPosition, delay, 0, loopCount);
        }

        internal static void OnTweenLocalPosition(TweenerCore<Vector3> tweener)
        {
            if (tweener.Component is Transform)
            {
                Transform transform = tweener.Component as Transform;
                transform.localPosition = tweener.Value;
            }
        }

        /// <summary>
        /// 渐变eulerAngles
        /// </summary>
        /// <param name="transform">Transform对象</param>
        /// <param name="target">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义的缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟</param>
        /// <param name="loopCount">循环次数</param>
        /// <returns></returns>
        public static TweenerCore<Vector3> TweenEulerAngles(this Transform transform, Vector3 target, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1)
        { 
            return TweenManager.ComponentTween(transform, transform.eulerAngles, target, duration, loop, ease, curve, ingoreTimeScale, OnTweenEulerAngles, delay, 0, loopCount);
        }

        internal static void OnTweenEulerAngles(TweenerCore<Vector3> tweener)
        {
            if (tweener.Component is Transform)
            {
                Transform transform = tweener.Component as Transform;
                transform.eulerAngles = tweener.Value;
            }
        }

        /// <summary>
        /// 渐变localEulerAngles
        /// </summary>
        /// <param name="transform">Transform对象</param>
        /// <param name="target">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义的缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟</param>
        /// <param name="loopCount">循环次数</param>
        /// <returns></returns>
        public static TweenerCore<Vector3> TweenLocalEulerAngles(this Transform transform, Vector3 target, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1)
        {
            return TweenManager.ComponentTween(transform, transform.localEulerAngles, target, duration, loop, ease, curve, ingoreTimeScale, OnTweenLocalEulerAngles, delay, 0, loopCount);
        }

        internal static void OnTweenLocalEulerAngles(TweenerCore<Vector3> tweener)
        {
            if (tweener.Component is Transform)
            {
                Transform transform = tweener.Component as Transform;
                transform.localEulerAngles = tweener.Value;
            }
        }

        /// <summary>
        /// 渐变rotation
        /// </summary>
        /// <param name="transform">Transform对象</param>
        /// <param name="target">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义的缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟</param>
        /// <param name="loopCount">循环次数</param>
        /// <returns></returns>
        public static TweenerCore<Quaternion> TweenRotation(this Transform transform, Quaternion target, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1)
        {
            return TweenManager.ComponentTween(transform, transform.rotation, target, duration, loop, ease, curve, ingoreTimeScale, OnTweenRotation, delay, 0, loopCount);
        }

        internal static void OnTweenRotation(TweenerCore<Quaternion> tweener)
        {
            if (tweener.Component is Transform)
            {
                Transform transform = tweener.Component as Transform;
                transform.rotation = tweener.Value;
            }
        }

        /// <summary>
        /// 渐变localRotation
        /// </summary>
        /// <param name="transform">Transform对象</param>
        /// <param name="target">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义的缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟</param>
        /// <param name="loopCount">循环次数</param>
        /// <returns></returns>
        public static TweenerCore<Quaternion> TweenLocalRotation(this Transform transform, Quaternion target, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1)
        {
            return TweenManager.ComponentTween(transform, transform.localRotation, target, duration, loop, ease, curve, ingoreTimeScale, OnTweenLocalRotation, delay, 0, loopCount);
        }

        internal static void OnTweenLocalRotation(TweenerCore<Quaternion> tweener)
        {
            if (tweener.Component is Transform)
            {
                Transform transform = tweener.Component as Transform;
                transform.localRotation = tweener.Value;
            }
        }

        /// <summary>
        /// 渐变localScale
        /// </summary>
        /// <param name="transform">Transform对象</param>
        /// <param name="target">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义的缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟</param>
        /// <param name="loopCount">循环次数</param>
        /// <returns></returns>
        public static TweenerCore<Vector3> TweenLocalScale(this Transform transform, Vector3 target, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1)
        { 
            return TweenManager.ComponentTween(transform, transform.localScale, target, duration, loop, ease, curve, ingoreTimeScale, OnTweenLocalScale, delay, 0, loopCount);
        }

        internal static void OnTweenLocalScale(TweenerCore<Vector3> tweener)
        {
            if (tweener.Component is Transform)
            {
                Transform transform = tweener.Component as Transform;
                transform.localScale = tweener.Value;
            }
        }

    }

}

